package com.qdu.servlet;


import com.qdu.impl.CommontImpl;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class CommontManage extends HttpServlet {

    public final static String CONTENTTYPE = "text/html;charset=gb2312";
    public final static String CHARACTERENCODING = "gb2312";


    public CommontManage() {
        super();
    }


    public void destroy() {
        super.destroy(); 

    }


    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        doPost(request, response);
    }


    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        request.setCharacterEncoding(this.CHARACTERENCODING);
        response.setContentType(this.CONTENTTYPE);
        HttpSession session = request.getSession();
        String name = (String) session.getAttribute("name");
        if (name == null) {
            request.getRequestDispatcher("admin/login.jsp").forward(request, response);
        } else {
            String method = request.getParameter("method").trim();
            CommontImpl cb = new CommontImpl();
                if (method.equals("delcommont")) {
                String str[] = request.getParameterValues("choose");
                if (str == null) {
                    request.setAttribute("message", "请选择操作对象！");
                    request.getRequestDispatcher("admin/commont.jsp").forward(request, response);
                } else {
                    int id = str.length;
                    for (int i = 0; i < str.length; i++) {
                        int  s = Integer.parseInt(str[i]);
                        id = s;
                    }
                    int i = cb.delCommon(id);
                    if (i == 1) {
                        request.setAttribute("message", "操作成功！");
                        request.getRequestDispatcher("admin/commont.jsp").forward(request, response);
                    } else {
                        request.setAttribute("message", "系统维护中，请稍后再试！");
                        request.getRequestDispatcher("admin/commont.jsp").forward(request, response);
                    }
                }
            }
        }
    }


    public void init() throws ServletException {
    }

}
